package com.klod.news.ext

import android.annotation.SuppressLint
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import kotlinx.coroutines.FlowPreview


@SuppressLint("ModifierFactoryUnreferencedReceiver")
fun Modifier.noRepeatClickable(
    enabled: Boolean = true,
    onClickLabel: String? = null,
    onClick: () -> Unit
): Modifier = composed {
    val lastClickTime = remember { mutableLongStateOf(0L) }
    val interval = 500L // 设置点击间隔为 500 毫秒

    Modifier.clickable(
        enabled = enabled,
        onClickLabel = onClickLabel,
        onClick = {
            val currentTime = System.currentTimeMillis()
            if (currentTime - lastClickTime.longValue > interval) {
                lastClickTime.longValue = currentTime
                onClick()
            }
        }
    )
}